<? FoundryView::includeTpl( 'global:header' ) ?>

<div id="content_area_leftInternal" style="width:90%">

<?php
		$start = 0;
		if( FoundryRequest::get( 'start', 'num' ) ) {
			$start = FoundryRequest::get( 'start', 'num' );
		}
		$model = FoundryController::model( 'net.mode3.imageBucket:image' );
		$images = $model->find( 'order by *added desc limit '.$start.',11' );		

?>

<center>
<table border="0" width="90%">
	<tr>
		<td style="width:33%;">
		<?php if( $start > 0 ) : ?><a href="<?=FoundryView::helperLinkTo('imageBucket/'.($start-10))?>"><img src="<?=Foundry::config('webpath')?>/images/admin/arrow_left" border="0" />Previous Page</a>
		<?php endif ?>
		</td>
		<td style="width:33%;text-align:center;">
			<?php
			
			?>Get images in category:<br />
			<select name="tag" onchange="viewTag(this)">
				<option value="0">Select a category</option>
			<?php foreach( $model->tags as $tag ) : ?>
				<option value="<?=$tag->uid?>"><?=$tag->name?></option>
			<?php endforeach ?>
			</select>
		</td>
		<td style="width:33%;text-align:right;">
		<?php if( count( $images ) == 11 ) : ?><a href="<?=FoundryView::helperLinkTo('imageBucket/'.($start+10))?>">Next Page<img src="<?=Foundry::config('webpath')?>/images/admin/arrow_right"  border="0" /></a>
		<?php endif ?></td>
	</tr>
</table>
<table border="0"><tr valign="top">
<? $max = 10; if( count( $images ) < 10 ) { $max = count( $images ); } ?>
<? $rowCount = 0 ?>
<? for( $i=0; $i<$max; $i++ ) : ?>
	<? $image = $images[$i] ?>
	
	<? if( $rowCount == 4 ) : ?>
		</tr>
		<tr valign="top">
		<? $rowCount = 0; ?>
	<? endif ?>
	<td style="padding:2px;">
		<a href="<?=$image->filePath?><?=$image->name?>"><img src="<?=$image->filePath?><?=$image->thumbNail?>" alt="<?=$image->name?>" style="border: 1px solid #000; margin: 2px; padding: 2px;"/></a><br />
		<?=$image->caption_markdown?><p />
		[<a href="<?=$image->filePath?><?=$image->name?>">Download</a>]<br />
	</td>
	<? $rowCount++ ?>
<? endfor ?>
</tr></table>
</center>


</div><!-- content_area_right -->

<script type="text/javascript">
	function viewTag( element ) {
		if( element.value ) {
			var url = "<?=Foundry::config('webpath')?>/index.php/imageBucket/tag/"+element.value;
			window.location = url;
		}
	}
</script>
<? FoundryView::includeTpl( 'global:footer' ) ?>